Ex008, Telephone directory (Using Table)
This is the first database exercise: a Telephone directory using Table database
component.
Table component enables you to access database tables such as Paradox tables, Access,
dBase, and other standard database tables.
Exercise 008 Telephone directory (Using Table)
1. Click on Database Desktop menu item, which existed at Tools menu.
2. At Database Desktop utility main menu select: File/New/Table/Paradox 7.
3. Enter these fields:
-----------------------------------
Field name |Type|Size|Key|
-----------------------------------
Number | A | 20 | * |
Name | A | 30 | |
Address | A | 40 | |
Notes | M | 150 | |
-----------------------------------
A: Alpha ( String field )
M: Memo field
4. Click Save As button.
5. Select DBDEMOS: Aliase.
6. Write 'Phone' on file name edit box.
7. Close Database Desktop and return to Delphi.
8. Drop a Table and DataSource from Data Access page.
9. On Table's DatabaseName property select DBDEMOS.
10. On Table's TableName property select phone.db.
11. On DataSource's DataSet property select Table1.
12. Drop: DBNavigator, 3 DBEdit, DBMemo from Data Controls page.
13. Select DataSource1 on DataSource property for all these new components you have
dropped from Data Controls page ( You can select all these components by mouse while
holding shift then double click DataSource property on Object Inspector).
14. On first DBEdit box select 'Name' on DataField property. Drop a Label and caption
it 'Name'.
15. On second DBEdit box select 'Number' on DataField property. Drop a Label and
caption it 'Number'.
16. On third DBEdit box select 'Address' on DataField property. Drop a Label and
caption it 'Address'.
17. On last DBMemo select 'Notes' on DataField property. Drop a Label and caption
it 'Notes'.
18. On Form's OnCreate event write:
Table1.Open;
You can open the table at design time by assigning True to table's Active property,
but it is recommended that you open the table at run time such as writing Table1.Open;
at OnClick Form's event.
19. Run the program then click (+) button to enter new records. Enter some data
then test navigator buttons. Navigator buttons are (from left to right):
First, Previous, Next, Last, Insert, Delete, Edit, Post (Save record), Cancel (Cancel
modification), and Refresh record.
If you want to display record counter follow these steps:
20. Drop a Label and name it 'laPos'.
21. On Table's AfterScroll event write:
laPos.Caption:= IntToStr(Table1.RecNo);
22. Run the program then test previous, first, last, and next buttons.
Notes:
- You can make your own navigator using buttons and table's methods such as Table.First;
to goto first record, other table navigators methods are: Last, Next, Prior, Edit, Insert, Delete, Cancel,
and Refresh.